<?php

function searchbar($submitname, $function)
{
   global $errmsg;
	     global $link;

   $username = "";
   $extraname = "";

   if (isset ($_POST["username"]))
   {
      $username = $_POST["username"];
   }
      if (isset ($_POST["extraname"]))
   {
      $extraname = $_POST["extraname"];
   }
  
   $formshow  = '<FORM METHOD="POST" ACTION="';
   
   if ($function == SEARCHEMPFUNCTION)
   {
      $formshow .= 'empsearch.php">';;
   }
   else if ($function == SEARCHVISFUNCTION)
   {
      $formshow .= 'vissearch.php">';;
   }
   else
   {
      $formshow .= 'inquser.php">';;
   }
   
   $formshow .= '<font color=red>'.$errmsg.'<br><br><br></font>';
   $formshow .= '<TABLE BORDER="0"><TR>';

   $formshow .= '<TR><TD>Query: ';
   $formshow .= '</TD>';
   $formshow .= '<TD><INPUT TYPE="TEXT" NAME="username" SIZE="26" value="'.$username.'" ';
   $formshow .= '></TD>';
   $formshow .= '<TD><INPUT TYPE="SUBMIT" VALUE="Search" NAME="submit"></TD></TR>';
   $formshow .= '<TR><TD>TimeLog: ';
   $formshow .= '</TD>';
   $formshow .= '<TD><INPUT TYPE="TEXT" NAME="extraname" SIZE="26" value="'.$extraname.'" ';
   $formshow .= '></TD>';
   $formshow .= '<TD><INPUT TYPE="SUBMIT" VALUE="Search" NAME="submit"></TD></TR>';
   $formshow .= '</TABLE></br>';
   
   $formshow .= '</FORM>';
   print $formshow;
}
//=========================================================================================================================================
function UserForm($submitname, $function)
{
   global $errmsg;

   $username = "";
   $lastname = "";
   $userid = "";

   if (isset ($_POST["username"]) && ($function == ADDFUNCTION))
   {
      $username = $_POST["username"];
      $lastname = $_POST["lastname"];
  
   }

   if (($function == EDITFUNCTION) || ($function == DELETEFUNCTION) || ($function == INQUIREFUNCTION))
   {
      $username = $_POST["username"];

      if (isset ($_POST["lastname"]))
      {
         $lastname = $_POST["lastname"];
      }
		if (isset ($_POST["userid"]))
      {
         $userid = $_POST["userid"];
      }
      else
      {
         $lastname = getUserNameFromDB();
         $userid = getUserIDFromDB();
      }
   }

   $formshow  = '<FORM METHOD="POST" ACTION="';
   
   if ($function == ADDFUNCTION)
   {
      $formshow .= 'createuser.php">';;
   }
   elseif ($function == EDITFUNCTION)
   {
      $formshow .= 'edituser.php">';;
   }
   elseif ($function == DELETEFUNCTION)
   {
      $formshow .= 'deluser.php">';;
   }
   else
   {
      $formshow .= 'inquser.php">';;
   }
   
   $formshow .= '<font color=red>'.$errmsg.'<br><br><br></font>';
   $formshow .= '<TABLE BORDER="0"><TR>';

   if ($function == EDITFUNCTION){
 		$formshow .= '<TD width="250">User ID';
		$formshow .= '</TD>';
		$formshow .= '<TD><INPUT TYPE="TEXT" NAME="userid" SIZE="10" value="'.$userid.'"';
        $formshow .= 'READONLY></TD></TR>';
   }
 
   $formshow .= '<TR><TD>User Name';

   if ($function == ADDFUNCTION || $function == EDITFUNCTION)
   {
      $formshow .= '<font color="red">*</font>';
   }

   $formshow .= '</TD>';

   $formshow .= '<TD><INPUT TYPE="TEXT" NAME="username" SIZE="26" value="'.$username.'" ';

   if ($function == ADDFUNCTION)
   {
      $formshow .= '></TD></TR>';
   }
   else
   {
      $formshow .= 'READONLY></TD></TR>';
   }
   
   $formshow .= '<TR><TD>Last Name';

   if ($function == ADDFUNCTION || $function == EDITFUNCTION)
   {
      $formshow .= '<font color="red">*</font>';
   }

   $formshow .= '</TD>';

   $formshow .= '<TD><INPUT TYPE="TEXT" NAME="lastname" SIZE="26" value="'.$lastname.'" ';

   if ($function == ADDFUNCTION || $function == EDITFUNCTION)
   {
      $formshow .= '></TD></TR>';
   }
   else
   {
      $formshow .= 'READONLY></TD></TR>';
   }
   
   if (($function == ADDFUNCTION) || ($function == EDITFUNCTION))
   {
      $formshow .= '<TR><TD>Password';

      if ($function == ADDFUNCTION)
      {
         $formshow .= '<font color="red">*</font>';
      }

      $formshow .= '</TD>';

      $formshow .= '<TD><INPUT TYPE="password" NAME="password" SIZE="26"></TD></TR>';
      $formshow .= '<TR><TD>Confirm Password';

      if ($function == ADDFUNCTION)
      {
         $formshow .= '<font color="red">*</font>';
      }

      $formshow .= '</TD>';
      
      $formshow .= '<TD><INPUT TYPE="password" NAME="confirmpassword" SIZE="26"></TD></TR>';
   }

   $formshow .= '</TABLE></br>';
   $formshow .= '<font size=2; color=red> * The following fields are Required</font>';
   if (($errmsg != userSaved) && ($function != INQUIREFUNCTION))
   {
      $formshow .= '<P ALIGN=CENTER><BR><BR><INPUT TYPE="SUBMIT" VALUE="'.$submitname.'" NAME="submit"></P>';
	  
   }
  
   $formshow .= '</FORM>';

   print $formshow;
}
//=========================================================================================================================================
function showUserForm3($submitname, $function)
{
   global $errmsg;

   $firstname = "";
   $lastname = "";
   $empid = "";
 
      $firstname = $_POST["firstname"];
      if (isset ($_POST["lastname"]))
      {
         $lastname = $_POST["lastname"];
      $empid = $_POST["empid"];
      }
	   else
      {
         $lastname = getEmpLNameFromDB();
         $empid = getEmpIDFromDB();
	  }

   $formshow  = '<FORM METHOD="POST" ACTION="';
   
   if ($function == TIMEINEMP)
   {
      $formshow .= 'emptimein.php">';;
   }
   else
   {
      $formshow .= 'inquser.php">';;
   }
   
   $formshow .= '<font color=red>'.$errmsg.'<br><br><br></font>';
   $formshow .= '<TABLE BORDER="0"><TR>';
		$formshow .= '<TD width="250">Employee ID';
   $formshow .= '</TD>';
   $formshow .= '<TD><INPUT TYPE="TEXT" NAME="empid" SIZE="10" value="'.$empid.'" ';
   $formshow .= 'READONLY></TD></TR>';
		$formshow .= '<TR><TD>First Name';
   $formshow .= '</TD>';
   $formshow .= '<TD><INPUT TYPE="TEXT" NAME="firstname" SIZE="26" value="'.$firstname.'" ';
   $formshow .= 'READONLY></TD></TR>';
		$formshow .= '<TR><TD>Last Name';
   $formshow .= '</TD>';
   $formshow .= '<TD><INPUT TYPE="TEXT" NAME="lastname" SIZE="26" value="'.$lastname.'" ';
   $formshow .= 'READONLY></TD></TR>';
  
   $formshow .= '<TD>Period</TD>';
   $formshow .= '<TD><input type="Text" id=fromdate name=fromdate maxlength="25" size="19">';
   $formshow .= '<a href="javascript:NewCal(\'fromdate\',\'MMDDYYYY\',true,12)">';
   $formshow .= '<img src="images/cal.gif" width="16" height="16" border="0" alt="Pick a date"></a>';
   $formshow .= ' - <input type="Text" id=todate name=todate maxlength="25" size="19">';
   $formshow .= '<a href="javascript:NewCal(\'todate\',\'MMDDYYYY\',true,12)">';
   $formshow .= '<img src="images/cal.gif" width="16" height="16" border="0" alt="Pick a date"></a></TD></TR>';
   $formshow .= '<TD><TD><font color=red>mm-dd-yy</font>';
   $formshow .= '</TABLE>';
   $formshow .= '<P ALIGN=CENTER><BR><BR><INPUT TYPE="SUBMIT" VALUE="'.$submitname.'" NAME="submit"></P>';
   $formshow .= '</FORM>';
   $formshow .= '</TABLE></br>';

   print $formshow;
}
//=========================================================================================================================================
//=========================================================================================================================================
function showUserForm2($submitname, $function)
{
   global $errmsg;

   $firstname = "";
   $lastname = "";
   $empid = "";
   $address = "";
   $position = "";
   $doorno = "";

   if (isset ($_POST["firstname"]) && ($function == ADDFUNCTION))
   {
      $firstname = $_POST["firstname"];
      $lastname = $_POST["lastname"];
   }

   if (($function == EDITFUNCTION) || ($function == DELETEFUNCTION) || ($function == INQUIREFUNCTION))
   {
      $firstname = $_POST["firstname"];

      if (isset ($_POST["lastname"]))
      {
         $lastname = $_POST["lastname"];
      }
	   else
      {
         $lastname = getEmpLNameFromDB();
         $empid = getEmpIDFromDB();
         $address = getEmpAddFromDB();
         $position = getEmpPosFromDB();
         $doorno = getEmpDoorFromDB();
		 
      }
   }

   $formshow  = '<FORM METHOD="POST" ACTION="';
   
   if ($function == ADDFUNCTION)
   {
      $formshow .= 'addemployee.php">';;
   }
   elseif ($function == EDITFUNCTION)
   {
      $formshow .= 'editemployee.php">';;
   }
   elseif ($function == DELETEFUNCTION)
   {
      $formshow .= 'deluser.php">';;
   }
   else
   {
      $formshow .= 'inquser.php">';;
   }
   
   $formshow .= '<font color=red>'.$errmsg.'<br><br><br></font>';
   $formshow .= '<TABLE BORDER="0"><TR>';
   
   if ($function == EDITFUNCTION)
   {
		$formshow .= '<TD width="250">Employee ID';
		$formshow .= '</TD>';
		$formshow .= '<TD><INPUT TYPE="TEXT" NAME="empid" SIZE="10" value="'.$empid.'" ';
		$formshow .= 'READONLY></TD></TR>';
   }
   
    $formshow .= '<TR><TD>First Name';

   if ($function == ADDFUNCTION || $function == EDITFUNCTION)
   {
      $formshow .= '<font color="red">*</font>';
   }

   $formshow .= '</TD>';
   $formshow .= '<TD><INPUT TYPE="TEXT" NAME="firstname" SIZE="26" value="'.$firstname.'" ';

   if ($function == ADDFUNCTION || $function == EDITFUNCTION)
   {
      $formshow .= '></TD></TR>';
   }
   else
   {
      $formshow .= 'READONLY></TD></TR>';
   }
   
   $formshow .= '<TR><TD>Last Name';

   if ($function == ADDFUNCTION || $function == EDITFUNCTION)
   {
      $formshow .= '<font color="red">*</font>';
   }

   $formshow .= '</TD>';
   $formshow .= '<TD><INPUT TYPE="TEXT" NAME="lastname" SIZE="26" value="'.$lastname.'" ';

   if ($function == ADDFUNCTION || $function == EDITFUNCTION)
   {
      $formshow .= '></TD></TR>';
   }
   else
   {
      $formshow .= 'READONLY></TD></TR>';
   }
   
   if (($function == ADDFUNCTION) || ($function == EDITFUNCTION))
   {
      $formshow .= '<TR><TD>Address';

      if ($function == ADDFUNCTION)
      {
         $formshow .= '<font color="red">*</font>';
      }

      $formshow .= '</TD>';

      $formshow .= '<TD><INPUT TYPE="TEXT" NAME="address" SIZE="50" value="'.$address.'"></TD></TR>';
      $formshow .= '<TR><TD>Position';

      if ($function == ADDFUNCTION)
      {
         $formshow .= '<font color="red">*</font>';
      }

      $formshow .= '</TD>';
      $formshow .= '<TD><INPUT TYPE="TEXT" NAME="position" SIZE="26" value="'.$position.'"></TD></TR>';
      $formshow .= '<TR><TD>Door No';

      if ($function == ADDFUNCTION)
      {
         $formshow .= '<font color="red">*</font>';
      }
      $formshow .= '</TD>';
      $formshow .= '<TD><INPUT TYPE="TEXT" NAME="doorno" SIZE="10" value="'.$doorno.'"></TD></TR>';
	 }

   $formshow .= '</TABLE></br>';
   $formshow .= '<font size=2; color=red> * The following fields are Required</font>';
   if (($errmsg != EmpSaved) && ($function != INQUIREFUNCTION))
   {
      $formshow .= '<P ALIGN=CENTER><BR><BR><INPUT TYPE="SUBMIT" VALUE="'.$submitname.'" NAME="submit"></P>';
   }
  
   $formshow .= '</FORM>';

   print $formshow;
}
//=========================================================================================================================================
function showVisForm2($submitname, $function)
{
   global $errmsg;

   $firstname = "";
   $lastname = "";
   $visid = "";
   $phoneno = "";

      $firstname = $_POST["firstname"];

      if (isset ($_POST["lastname"]))
      {
         $lastname = $_POST["lastname"];
         $visid = $_POST["visid"];
         $phoneno = $_POST["phoneno"];
      }
	  else
      {
         $lastname = getVisLNameFromDB();
         $visid = getVisIDFromDB();
         $phoneno = getVisPhoneFromDB();
       }
  
   $formshow  = '<FORM METHOD="POST" ACTION="';
   
   if ($function == TIMEINVIS)
   {
      $formshow .= 'vistimein.php">';;
   }
   else
   {
      $formshow .= 'inquser.php">';;
   }
   
   $formshow .= '<font color=red>'.$errmsg.'<br><br><br></font>';
   $formshow .= '<TABLE BORDER="0"><TR>';
   $formshow .= '<TD width="250">Visitor ID';
   $formshow .= '</TD>';
   $formshow .= '<TD><INPUT TYPE="TEXT" NAME="visid" SIZE="10" value="'.$visid.'"';

   $formshow .= 'READONLY></TD></TR>';
  
   $formshow .= '<TR><TD>First Name';

   $formshow .= '</TD>';

   $formshow .= '<TD><INPUT TYPE="TEXT" NAME="firstname" SIZE="26" value="'.$firstname.'" ';

   $formshow .= 'READONLY></TD></TR>';
  
   $formshow .= '<TR><TD>Last Name';

   $formshow .= '</TD>';

   $formshow .= '<TD><INPUT TYPE="TEXT" NAME="lastname" SIZE="26" value="'.$lastname.'" ';

   $formshow .= 'READONLY></TD></TR>';
   
   $formshow .= '<TR><TD>Phone No';

   $formshow .= '</TD>';

   $formshow .= '<TD><INPUT TYPE="TEXT" NAME="phoneno" SIZE="26" value="'.$phoneno.'"';
   $formshow .= 'READONLY></TD></TR>';

   $formshow .= '<TD>Period</TD>';
   $formshow .= '<TD><input type="Text" id=fromdate name=fromdate maxlength="25" size="19">';
   $formshow .= '<a href="javascript:NewCal(\'fromdate\',\'MMDDYYYY\',true,12)">';
   $formshow .= '<img src="images/cal.gif" width="16" height="16" border="0" alt="Pick a date"></a>';
   $formshow .= ' - <input type="Text" id=todate name=todate maxlength="25" size="19">';
   $formshow .= '<a href="javascript:NewCal(\'todate\',\'MMDDYYYY\',true,12)">';
   $formshow .= '<img src="images/cal.gif" width="16" height="16" border="0" alt="Pick a date"></a></TD></TR>';
   $formshow .= '<TD><TD><font color=red>mm-dd-yy</font>';
   $formshow .= '</TABLE>';
   $formshow .= '<P ALIGN=CENTER><BR><BR><INPUT TYPE="SUBMIT" VALUE="'.$submitname.'" NAME="submit"></P>';
   $formshow .= '</FORM>';
   $formshow .= '</TABLE></br>';

   print $formshow;
}
//=========================================================================================================================================
function showUserForm($submitname, $function)
{
   global $errmsg;

   $firstname = "";
   $lastname = "";
   $visid = "";
   $phoneno = "";
   $purpose = "";
   $address = "";
   $doorno = "";

   if (isset ($_POST["firstname"]) && ($function == ADDFUNCTION))
   {
      $firstname = $_POST["firstname"];
      $lastname = $_POST["lastname"];
   }

   if (($function == EDITFUNCTION) || ($function == DELETEFUNCTION) || ($function == INQUIREFUNCTION))
   {
      $firstname = $_POST["firstname"];

      if (isset ($_POST["lastname"]))
      {
         $lastname = $_POST["lastname"];
      }
	  else
      {
         $lastname = getVisLNameFromDB();
         $visid = getVisIDFromDB();
         $phoneno = getVisPhoneFromDB();
         $purpose = getVisPurFromDB();
         $address = getVisAddFromDB();
         $doorno = getVisDoorFromDB();
      }
   }

   $formshow  = '<FORM METHOD="POST" ACTION="';
   
   if ($function == ADDFUNCTION)
   {
      $formshow .= 'addvisitor.php">';;
   }
   elseif ($function == EDITFUNCTION)
   {
      $formshow .= 'editvisitor.php">';;
   }
   elseif ($function == DELETEFUNCTION)
   {
      $formshow .= 'deluser.php">';;
   }
   else
   {
      $formshow .= 'inquser.php">';;
   }
   
   $formshow .= '<font color=red>'.$errmsg.'<br><br><br></font>';
   $formshow .= '<TABLE BORDER="0"><TR>';
   
   if ($function == EDITFUNCTION)
   {
		$formshow .= '<TD width="250">Visitor ID';
		$formshow .= '</TD>';
		$formshow .= '<TD><INPUT TYPE="TEXT" NAME="visid" SIZE="10" value="'.$visid.'"';
		$formshow .= 'READONLY></TD></TR>';
   }
   
    $formshow .= '<TR><TD>First Name';

   if ($function == ADDFUNCTION || $function == EDITFUNCTION)
   {
      $formshow .= '<font color="red">*</font>';
   }

   $formshow .= '</TD>';
   $formshow .= '<TD><INPUT TYPE="TEXT" NAME="firstname" SIZE="26" value="'.$firstname.'" ';

   if ($function == ADDFUNCTION || $function == EDITFUNCTION)
   {
      $formshow .= '></TD></TR>';
   }
   else
   {
      $formshow .= 'READONLY></TD></TR>';
   }
   
   $formshow .= '<TR><TD>Last Name';

   if ($function == ADDFUNCTION || $function == EDITFUNCTION)
   {
      $formshow .= '<font color="red">*</font>';
   }

   $formshow .= '</TD>';
   $formshow .= '<TD><INPUT TYPE="TEXT" NAME="lastname" SIZE="26" value="'.$lastname.'" ';

   if ($function == ADDFUNCTION || $function == EDITFUNCTION)
   {
      $formshow .= '></TD></TR>';
   }
   else
   {
      $formshow .= 'READONLY></TD></TR>';
   }
   
   if (($function == ADDFUNCTION) || ($function == EDITFUNCTION))
   {
      $formshow .= '<TR><TD>Phone No';

      if ($function == ADDFUNCTION)
      {
         $formshow .= '<font color="red">*</font>';
      }

      $formshow .= '</TD>';

      $formshow .= '<TD><INPUT TYPE="TEXT" NAME="phoneno" SIZE="26" value="'.$phoneno.'"></TD></TR>';
      $formshow .= '<TR><TD>Purpose';

      if ($function == ADDFUNCTION)
      {
         $formshow .= '<font color="red">*</font>';
      }

      $formshow .= '</TD>';
      
      $formshow .= '<TD><INPUT TYPE="TEXT" NAME="purpose" SIZE="26" value="'.$purpose.'"></TD></TR>';
      $formshow .= '<TR><TD>Address';

      if ($function == ADDFUNCTION)
      {
         $formshow .= '<font color="red">*</font>';
      }

      $formshow .= '</TD>';
      
      $formshow .= '<TD><INPUT TYPE="TEXT" NAME="address" SIZE="50" value="'.$address.'"></TD></TR>';
	        $formshow .= '<TR><TD>Door No';

      if ($function == ADDFUNCTION)
      {
         $formshow .= '<font color="red">*</font>';
      }

      $formshow .= '</TD>';
      
      $formshow .= '<TD><INPUT TYPE="TEXT" NAME="doorno" SIZE="10" value="'.$doorno.'"></TD></TR>';

	 }

   $formshow .= '</TABLE></br>';
   $formshow .= '<font size=2; color=red> * The following fields are Required</font>';
   if (($errmsg != visadded) && ($function != INQUIREFUNCTION))
   {
      $formshow .= '<P ALIGN=CENTER><BR><BR><INPUT TYPE="SUBMIT" VALUE="'.$submitname.'" NAME="submit"></P>';
   }
  
   $formshow .= '</FORM>';

   print $formshow;
}
//=========================================================================================================================================
function showUserList55($submitname, $function)
{
   global $errmsg;

   $formshow  = '<FORM METHOD="POST" ACTION="';
   
   if ($function == EDITFUNCTION)
   {
      $formshow  .= 'edituser.php">';
   }
   elseif ($function == DELETEFUNCTION)
   {
      $formshow  .= 'deluser.php">';
   }
   else
   {
      $formshow  .= 'inquser.php">';
   }
   
   $formshow .= '<font color=red>'.$errmsg.'<br><br><br></font>';
   $formshow .= '<TABLE BORDER="0"><TR>';
   $formshow .= '<TD width="250">User Name</font></TD>';
   $formshow .= '<TD><SELECT name="username">';
   $formshow .= UserListFromDBToSelect1();
   $formshow .= '</SELECT></TD></TR>';
   $formshow .= '</TABLE>';
   $formshow .= '<P ALIGN=CENTER><BR><BR><INPUT TYPE="SUBMIT" onclick="return confirm(\'Are You Sure?\')" VALUE="'.$submitname.'" NAME="submit"></P>';
   $formshow .= '</FORM>';

   print $formshow;
}
//=========================================================================================================================================
function showUserList($submitname, $function)
{
   global $errmsg;

   $formshow  = '<FORM METHOD="POST" ACTION="';
   
   if ($function == EDITFUNCTION)
   {
      $formshow  .= 'edituser.php">';
   }
   elseif ($function == DELETEFUNCTION)
   {
      $formshow  .= 'deluser.php">';
   }
   else
   {
      $formshow  .= 'inquser.php">';
   }
   
   $formshow .= '<font color=red>'.$errmsg.'<br><br><br></font>';
   $formshow .= '<TABLE BORDER="0"><TR>';
   $formshow .= '<TD width="250">User Name</font></TD>';
   $formshow .= '<TD><SELECT name="username">';
   $formshow .= UserListFromDBToSelect2();
   $formshow .= '</SELECT></TD></TR>';
   $formshow .= '</TABLE>';
   $formshow .= '<P ALIGN=CENTER><BR><BR><INPUT TYPE="SUBMIT" onclick="return confirm(\'Are You Sure?\')" VALUE="'.$submitname.'" NAME="submit"></P>';
   $formshow .= '</FORM>';

   print $formshow;
}
//=========================================================================================================================================
function showEmpList2($submitname, $function)
{
   global $errmsg;

   $formshow  = '<FORM METHOD="POST" ACTION="';
   
   if ($function == EDITFUNCTION)
   {
      $formshow  .= 'editemployee.php">';
   }
   elseif ($function == DELETEFUNCTION)
   {
      $formshow  .= 'delemployee.php">';
   }
   else
   {
      $formshow  .= 'inquser.php">';
   }
   
   $formshow .= '<font color=red>'.$errmsg.'<br><br><br></font>';
   $formshow .= '<TABLE BORDER="0"><TR>';
   $formshow .= '<TD width="250">Employee Name</font></TD>';
   $formshow .= '<TD><SELECT name="username">';
   $formshow .= EmpListFromDBToSelect();
   $formshow .= '</SELECT></TD></TR>';
   $formshow .= '</TABLE>';
   $formshow .= '<P ALIGN=CENTER><BR><BR><INPUT TYPE="SUBMIT" onclick="return confirm(\'Are You Sure?\')" VALUE="'.$submitname.'" NAME="submit"></P>';
   $formshow .= '</FORM>';

   print $formshow;
}
//=========================================================================================================================================
function showVisList($submitname, $function)
{
   global $errmsg;

   $formshow  = '<FORM METHOD="POST" ACTION="';
   
   if ($function == EDITFUNCTION)
   {
      $formshow  .= 'editvisitor.php">';
   }
   elseif ($function == DELETEFUNCTION)
   {
      $formshow  .= 'delemployee.php">';
   }
   elseif ($function == TIMEFUNCTION)
   {
      $formshow  .= 'vistimein.php">';
   }
   else
   {
      $formshow  .= 'inquser.php">';
   }
   
   $formshow .= '<font color=red>'.$errmsg.'<br><br><br></font>';
   $formshow .= '<TABLE BORDER="0"><TR>';
   $formshow .= '<TD width="250">Visitor Name</font></TD>';
   $formshow .= '<TD><SELECT name="firstname">';
   $formshow .= VisListFromDBToSelect();
   $formshow .= '</SELECT></TD></TR>';
   $formshow .= '</TABLE>';
   $formshow .= '<P ALIGN=CENTER><BR><BR><INPUT TYPE="SUBMIT" VALUE="'.$submitname.'" NAME="submit"></P>';
   $formshow .= '</FORM>';

   print $formshow;
}
//========================================================================
function VisListFromDBToSelect()
{
   global $link;

   $sql  = "select Visitor_ID, First_Name, Last_Name, Purpose from visitorlist order by Last_Name";

   $result=mysql_query($sql,$link);

   if (!$result)
   {
      die("Mysql List user to DB error...".$sql);
   }

   $select = "";
   
   while($data=mysql_fetch_array($result,MYSQL_ASSOC))
   {
      $select .= '<option value="'.$data["First_Name"].'">';
      $select .= $data["Visitor_ID"].' - '.$data["Last_Name"].' , '.$data["First_Name"].' - '.$data["Purpose"].'</option>';
   }

   return($select);
}
//=========================================================================================================================================
function showEmpList($submitname, $function)
{
   global $errmsg;

   $formshow  = '<FORM METHOD="POST" ACTION="';
   
   if ($function == EDITFUNCTION)
   {
      $formshow  .= 'editemployee.php">';
   }
   elseif ($function == DELETEFUNCTION)
   {
      $formshow  .= 'delemployee.php">';
   }
   elseif ($function == TIMEFUNCTION)
   {
      $formshow  .= 'emptimein.php">';
   }
   else
   {
      $formshow  .= 'inquser.php">';
   }
   
   $formshow .= '<font color=red>'.$errmsg.'<br><br><br></font>';
   $formshow .= '<TABLE BORDER="0"><TR>';
   $formshow .= '<TD width="250">Employee Name</font></TD>';
   $formshow .= '<TD><SELECT name="firstname">';
   $formshow .= EmpListFromDBToSelect();
   $formshow .= '</SELECT></TD></TR>';
   $formshow .= '</TABLE>';
   $formshow .= '<P ALIGN=CENTER><BR><BR><INPUT TYPE="SUBMIT" VALUE="'.$submitname.'" NAME="submit"></P>';
   $formshow .= '</FORM>';

   print $formshow;
}
//========================================================================
function EmpListFromDBToSelect()
{
   global $link;

   $sql  = "select Employee_ID, First_Name, Last_Name, Position from employeelist order by Last_Name";

   $result=mysql_query($sql,$link);

   if (!$result)
   {
      die("Mysql List user to DB error...".$sql);
   }

   $select = "";
   
   while($data=mysql_fetch_array($result,MYSQL_ASSOC))
   {
      $select .= '<option value="'.$data["First_Name"].'">';
      $select .= $data["Employee_ID"].' - '.$data["Last_Name"].' , '.$data["First_Name"].' - '.$data["Position"].'</option>';
   }

   return($select);
}
//========================================================================
function UserListFromDBToSelect1()
{
   global $link;

   $sql  = "select userid, User_Name, Last_Name from userlist where User_Name !='admin' order by userid";

   $result=mysql_query($sql,$link);

   if (!$result)
   {
      die("Mysql List user to DB error...".$sql);
   }

   $select = "";
   
   while($data=mysql_fetch_array($result,MYSQL_ASSOC))
   {
      $select .= '<option value="'.$data["User_Name"].'">';
      $select .= $data["userid"].' - '.$data["User_Name"].' - '.$data["Last_Name"].'</option>';
   }

   return($select);
}
//========================================================================
function UserListFromDBToSelect2()
{
   global $link;

   $sql  = "select userid, User_Name, Last_Name from userlist order by userid";

   $result=mysql_query($sql,$link);

   if (!$result)
   {
      die("Mysql List user to DB error...".$sql);
   }

   $select = "";
   
   while($data=mysql_fetch_array($result,MYSQL_ASSOC))
   {
      $select .= '<option value="'.$data["User_Name"].'">';
      $select .= $data["userid"].' - '.$data["User_Name"].' - '.$data["Last_Name"].'</option>';
   }

   return($select);
}
//==============================================================
function deleteEmpFromDB()
{
   global $link;

   $result=mysql_query("delete from employeelist where First_Name='".addslashes($_POST["username"])."'",$link);

   if (!$result)
   {
      die("Mysql Select User DB error...");
   }
}
//==============================================================
function deleteUserFromDB()
{
   global $link;

   $result=mysql_query("delete from userlist where User_Name='".addslashes($_POST["username"])."'",$link);

   if (!$result)
   {
      die("Mysql Select User DB error...");
   }
}
//=========================================================================================================================================
function validateVisForm($submitname)
{
   global $link;
   global $errmsg;
      $doorno = ($_POST["doorno"]);

   
   $errmsg = '';

   if ((strlen($_POST["firstname"]) == 0) && ($submitname == ADDVISSUBMITTEXT))
   {
      $errmsg = "Please enter Visitor's First Name.";
      return(false);
   }
   if ((strlen($_POST["lastname"]) == 0) && ($submitname == ADDVISSUBMITTEXT))
   {
      $errmsg = "Please enter Visitor's Last Name.";
      return(false);
   }
   if ((strlen($_POST["address"]) == 0) && ($submitname == ADDVISSUBMITTEXT))
   {
      $errmsg = "Please enter Visitor's Address.";
      return(false);
   }
   if ((strlen($_POST["phoneno"]) == 0) && ($submitname == ADDVISSUBMITTEXT))
   {
      $errmsg = "Please enter Visitor's Phone No.";
      return(false);
   }
   if ((strlen($_POST["purpose"]) == 0) && ($submitname == ADDVISSUBMITTEXT))
   {
      $errmsg = "Please enter Visitor's Purpose.";
      return(false);
   }
   if ((strlen($_POST["doorno"]) == 0) && ($submitname == ADDVISSUBMITTEXT))
   {
      $errmsg = "Please enter Visitor's Door Number.";
      return(false);
   }
         if ($doorno<1 || $doorno>3)
   {
      $errmsg = "Please enter the correct Door Number";
      return(false);
   }
  
   $result=mysql_query("select * from visitorlist where First_Name='".addslashes($_POST["firstname"])."'",$link);
   $result2=mysql_query("select * from visitorlist where Last_Name='".addslashes($_POST["lastname"])."'",$link);

   if (!$result)
   {
      die("Mysql Select User DB error...");
   }
   if (!$result2)
   {
      die("Mysql Select User DB error...");
   }
   
   if (mysql_num_rows($result) > 0 && mysql_num_rows($result2) > 0 && ($_POST["submit"] == ADDVISSUBMITTEXT))
   {
      $errmsg = "Visitor already exist...";
      return(false);
   }
  
   if ((mysql_num_rows($result) == 0) && ($_POST["submit"] == SAVEVISSUBMITTEXT))
   {
      $errmsg = "Visitor does not exist...";
      return(false);
   }

   return(true);
}
//=========================================================================================================================================
function validateEmpForm($submitname)
{
   global $link;
   global $errmsg;
   $doorno = ($_POST["doorno"]);
   $errmsg = '';
	
   if ((strlen($_POST["firstname"]) == 0) && ($submitname == ADDEMPSUBMITTEXT))
   {
      $errmsg = "Please enter Employee's First Name.";
      return(false);
   }
   if ((strlen($_POST["lastname"]) == 0) && ($submitname == ADDEMPSUBMITTEXT))
   {
      $errmsg = "Please enter Employee's Last Name.";
      return(false);
   }
   if ((strlen($_POST["address"]) == 0) && ($submitname == ADDEMPSUBMITTEXT))
   {
      $errmsg = "Please enter Employee's Address.";
      return(false);
   }
   if ((strlen($_POST["position"]) == 0) && ($submitname == ADDEMPSUBMITTEXT))
   {
      $errmsg = "Please enter Employee's Position.";
      return(false);
   }
   if ((strlen($_POST["doorno"]) == 0) && ($submitname == ADDEMPSUBMITTEXT))
   {
      $errmsg = "Please enter Employee's Door Number.";
      return(false);
   }
      if ($doorno<1 || $doorno>3)
   {
      $errmsg = "Please enter the correct Door Number";
      return(false);
   }


   $result=mysql_query("select * from employeelist where First_Name='".addslashes($_POST["firstname"])."'",$link);
   $result2=mysql_query("select * from employeelist where Last_Name='".addslashes($_POST["lastname"])."'",$link);

   if (!$result)
   {
      die("Mysql Select User DB error...");
   }
   if (!$result2)
   {
      die("Mysql Select User DB error...");
   }
   
   if (mysql_num_rows($result) > 0 && mysql_num_rows($result2) > 0 && ($_POST["submit"] == ADDEMPSUBMITTEXT))
   {
      $errmsg = "Employee already exist...";
      return(false);
   }
  
   if ((mysql_num_rows($result) == 0) && ($_POST["submit"] == SAVEEMPSUBMITTEXT))
   {
      $errmsg = "Employee does not exist...";
      return(false);
   }

   return(true);
}
//=========================================================================================================================================
function validateUserForm($submitname)
{
   global $link;
   global $errmsg;
   
   $errmsg = '';

   if ((strlen($_POST["username"]) == 0) && ($submitname == ADDUSERSUBMITTEXT))
   {
      $errmsg = "Please enter user name.";
      return(false);
   }

   if (strlen($_POST["lastname"]) == 0)
   {
      $errmsg = "Please enter last name.";
      return(false);
   }

   if ((strlen($_POST["password"]) == 0) && ($submitname == ADDUSERSUBMITTEXT || $submitname == EDITUSERSUBMITTEXT))
   {
      $errmsg = "Please enter password.";
      return(false);
   }
   

   if ($submitname == ADDUSERSUBMITTEXT || $submitname == EDITUSERSUBMITTEXT)
   {
      if ($_POST["password"] != $_POST["confirmpassword"])
      {
         $errmsg = "Password does not match.";
         return(false);
      }
   }

   $result=mysql_query("select * from userlist where User_Name='".addslashes($_POST["username"])."'",$link);

   if (!$result)
   {
      die("Mysql Select User DB error...");
   }
	
   if ((mysql_num_rows($result) > 0) && ($_POST["submit"] == ADDUSERSUBMITTEXT))
   {
      $errmsg = "User already exist...";
      return(false);
   }
  
   if ((mysql_num_rows($result) == 0) && ($_POST["submit"] == EDITUSERSUBMITTEXT))
   {
      $errmsg = "User does not exist...";
      return(false);
   }

   return(true);
}
//=========================================================================================================================================
function addUserToDB()
{
   global $link;
   
   $sql  = "insert into userlist set User_Name = '".addslashes($_POST["username"])."',";
   $sql .= "Last_Name = '".addslashes($_POST["lastname"])."',";
   $sql .= "Password = '".(addslashes($_POST["password"]))."'";

   $result=mysql_query($sql,$link);

   if (!$result)
   {
      die("Mysql Add user to DB error...".$sql);
   }
}
//=========================================================================================================================================
function addVisTimeToDB()
{
   global $link;
   
   $sql  = "insert into visitortime set Visitor_ID = '".addslashes($_POST["visid"])."',";
   $sql .= "First_Name = '".addslashes($_POST["firstname"])."',";
   $sql .= "Last_Name = '".addslashes($_POST["lastname"])."',";
   $sql .= "Phone_No = '".addslashes($_POST["phoneno"])."',";
   $sql .= "Time_In = '".addslashes($_POST["fromdate"])."',";
   $sql .= "Time_Out = '".(addslashes($_POST["todate"]))."'";

   $result=mysql_query($sql,$link);

   if (!$result)
   {
      die("Mysql Add user to DB error...".$sql);
   }
}
//=========================================================================================================================================
function addEmpTimeToDB()
{
   global $link;
   
   $sql  = "insert into employeetime set Employee_ID = '".addslashes($_POST["empid"])."',";
   $sql .= "First_Name = '".addslashes($_POST["firstname"])."',";
   $sql .= "Last_Name = '".addslashes($_POST["lastname"])."',";
   $sql .= "Time_In = '".addslashes($_POST["fromdate"])."',";
   $sql .= "Time_Out = '".(addslashes($_POST["todate"]))."'";

   $result=mysql_query($sql,$link);

   if (!$result)
   {
      die("Mysql Add user to DB error...".$sql);
   }
}
//=========================================================================================================================================
function addEmpToDB()
{
   global $link;
   
   $sql  = "insert into employeelist set First_Name = '".addslashes($_POST["firstname"])."',";
   $sql .= "Last_Name = '".addslashes($_POST["lastname"])."',";
   $sql .= "Address = '".addslashes($_POST["address"])."',";
   $sql .= "Position = '".addslashes($_POST["position"])."',";
   $sql .= "Door_No = '".(addslashes($_POST["doorno"]))."'";

   $result=mysql_query($sql,$link);

   if (!$result)
   {
      die("Mysql Add user to DB error...".$sql);
   }
}
//=========================================================================================================================================
function addVisToDB()
{
   global $link;
   
   $sql  = "insert into visitorlist set First_Name = '".addslashes($_POST["firstname"])."',";
   $sql .= "Last_Name = '".addslashes($_POST["lastname"])."',";
   $sql .= "Phone_No = '".addslashes($_POST["phoneno"])."',";
   $sql .= "Address = '".addslashes($_POST["address"])."',";
   $sql .= "Purpose = '".addslashes($_POST["purpose"])."',";
   $sql .= "Door_No = '".(addslashes($_POST["doorno"]))."'";

   $result=mysql_query($sql,$link);

   if (!$result)
   {
      die("Mysql Add user to DB error...".$sql);
   }
}
//=========================================================================================================================================
function updateVisToDB()
{
   global $link;

   $sql  = "update visitorlist set ";
   $sql .= "First_Name = '".addslashes($_POST["firstname"])."' ";
   $sql .= ",Last_Name = '".addslashes($_POST["lastname"])."' ";
   $sql .= ",Phone_No = '".addslashes($_POST["phoneno"])."' ";
   $sql .= ",Address = '".addslashes($_POST["address"])."' ";
   $sql .= ",Purpose = '".addslashes($_POST["purpose"])."' ";
   $sql .= ",Door_No = '".addslashes($_POST["doorno"])."' ";

   $sql .= "where Visitor_ID='".addslashes($_POST["visid"])."'";


   $result=mysql_query($sql,$link);

   if (!$result)
   {
      die("Mysql Update user to DB error...".$sql);
   }
}
//=========================================================================================================================================
function VisTimeList()
{
global $link;
   
   $sql  = "select Visitor_ID, First_Name, Last_Name, Phone_No, Time_In, Time_Out from visitortime";

   $result=mysql_query($sql,$link);

   if (!$result)
   {
      die("Mysql List user to DB error...".$sql);
   }
   
   $formshow  = '<TABLE BORDER="2" align=center><TR>';
   $formshow .= '<TD width="40" align=center><b><font color="#1569C7">Vis ID</font></TD>';
   $formshow .= '<TD width="140" align=center><b><font color="#1569C7">First Name</font></TD>';
   $formshow .= '<TD width="140" align=center><b><font color="#1569C7">Last Name</font></TD></b>';
   $formshow .= '<TD width="90" align=center><b><font color="#1569C7">Phone #</font></TD></b>';
   $formshow .= '<TD width="200" align=center><b><font color="#1569C7">Time In</font></TD>></b>';
   $formshow .= '<TD width="200" align=center><b><font color="#1569C7">Time Out</font></TD></TR></b>';

   while($data=mysql_fetch_array($result,MYSQL_ASSOC))
   {
      $formshow .= '<TR><TD><font face="arial" color="#1569C7" size=2>'.$data["Visitor_ID"].'<font></TD>';
      $formshow .= '<TD><font face="arial" color="#1569C7" size=2>'.$data["First_Name"].'<font></TD>';
      $formshow .= '<TD><font face="arial" color="#1569C7" size=2>'.$data["Last_Name"].'<font></TD>';
      $formshow .= '<TD><font face="arial" color="#1569C7" size=2>'.$data["Phone_No"].'<font></TD>';
      $formshow .= '<TD><font face="arial" color="#1569C7" size=2>'.$data["Time_In"].'<font></TD>';
      $formshow .= '<TD><font face="arial" color="#1569C7" size=2>'.$data["Time_Out"].'<font></TD></TR>';
   }

   $formshow .= '</TABLE>';
 
   print $formshow;
 }
//=========================================================================================================================================
function EmpTimeList()
{
global $link;
   
   $sql  = "select Employee_ID, First_Name, Last_Name, Time_In, Time_Out from employeetime";

   $result=mysql_query($sql,$link);

   if (!$result)
   {
      die("Mysql List user to DB error...".$sql);
   }

   $formshow  = '<TABLE BORDER="2" align=center><TR>';
   $formshow .= '<TD width="40" align=center><b><font color="#1569C7">Emp_ID</font></TD>';
   $formshow .= '<TD width="180" align=center><b><font color="#1569C7">First Name</font></TD>';
   $formshow .= '<TD width="180" align=center><b><font color="#1569C7">Last Name</font></TD></b>';
   $formshow .= '<TD width="200" align=center><b><font color="#1569C7">Time In</font></TD>></b>';
   $formshow .= '<TD width="200" align=center><b><font color="#1569C7">Time Out</font></TD></TR></b>';

   while($data=mysql_fetch_array($result,MYSQL_ASSOC))
   {
      $formshow .= '<TR><TD><font face="arial" color="#1569C7" size=2>'.$data["Employee_ID"].'<font></TD>';
      $formshow .= '<TD><font face="arial" color="#1569C7" size=2>'.$data["First_Name"].'<font></TD>';
      $formshow .= '<TD><font face="arial" color="#1569C7" size=2>'.$data["Last_Name"].'<font></TD>';
      $formshow .= '<TD><font face="arial" color="#1569C7" size=2>'.$data["Time_In"].'<font></TD>';
      $formshow .= '<TD><font face="arial" color="#1569C7" size=2>'.$data["Time_Out"].'<font></TD></TR>';
   }

   $formshow .= '</TABLE>';
 
   print $formshow;
 }
//=========================================================================================================================================
function updateEmpTime()
{
   global $link;

   $sql  = "update employeetime set ";
   $sql .= "First_Name = '".addslashes($_POST["firstname"])."' ";
   $sql .= ",Last_Name = '".addslashes($_POST["lastname"])."' ";
   $sql .= ",Time_In = '".addslashes($_POST["fromdate"])."' ";
   $sql .= ",Time_Out = '".addslashes($_POST["todate"])."' ";

   $sql .= "where Employee_ID='".addslashes($_POST["empid"])."'";

   $result=mysql_query($sql,$link);

   if (!$result)
   {
      die("Mysql Update user to DB error...".$sql);
   }
}
//=========================================================================================================================================
function updateEmpToDB()
{
   global $link;

   $sql  = "update employeelist set ";
   $sql .= "First_Name = '".addslashes($_POST["firstname"])."' ";
   $sql .= ",Last_Name = '".addslashes($_POST["lastname"])."' ";
   $sql .= ",Address = '".addslashes($_POST["address"])."' ";
   $sql .= ",Position = '".addslashes($_POST["position"])."' ";
   $sql .= ",Door_No = '".addslashes($_POST["doorno"])."' ";

   $sql .= "where Employee_ID='".addslashes($_POST["empid"])."'";


   $result=mysql_query($sql,$link);

   if (!$result)
   {
      die("Mysql Update user to DB error...".$sql);
   }
}
//=========================================================================================================================================
function updateUserToDB()
{
   global $link;

   $sql  = "update userlist set ";
     $sql .= "userid = '".addslashes($_POST["userid"])."' ";
   $sql .= ",Last_Name = '".addslashes($_POST["lastname"])."' ";

   if (strlen($_POST["password"]) > 0)
   {
      $sql .= ",Password = '".addslashes($_POST["password"])   ."' ";
   }

   $sql .= "where User_Name='".addslashes($_POST["username"])."'";


   $result=mysql_query($sql,$link);

   if (!$result)
   {
      die("Mysql Update user to DB error...".$sql);
   }
}
//----------------------------------------------------------------------
function getUserIDFromDB()
{
   global $link;

   $result=mysql_query("select * from userlist where User_Name='".addslashes($_POST["username"])."'",$link);

   if (!$result)
   {
      die("Mysql Select User DB error...");
   }

   if (mysql_num_rows($result) == 0)
   {
      die("DB Error...");
   }

   $data=mysql_fetch_array($result,MYSQL_ASSOC);
   
   return($data["userid"]);
}
//----------------------------------------------------------------------
function getFirstNameforsearch()
{
   global $link;

   $result=mysql_query("select * from employeelist where First_Name='".addslashes($_POST["username"])."'",$link);

   if (!$result)
   {
      die("Mysql Select User DB error...");
   }

   if (mysql_num_rows($result) == 0)
   {
      die("DB Error...");
   }

   $data=mysql_fetch_array($result,MYSQL_ASSOC);
   
   return($data["First_Name"]);
}
//----------------------------------------------------------------------
function getUserNameFromDB()
{
   global $link;

   $result=mysql_query("select * from userlist where User_Name='".addslashes($_POST["username"])."'",$link);

   if (!$result)
   {
      die("Mysql Select User DB error...");
   }

   if (mysql_num_rows($result) == 0)
   {
      die("DB Error...");
   }

   $data=mysql_fetch_array($result,MYSQL_ASSOC);
   
   return($data["Last_Name"]);
}
//----------------------------------------------------------------------
function getEmpLNameFromDB()
{
   global $link;

   $result=mysql_query("select * from employeelist where First_Name='".addslashes($_POST["firstname"])."'",$link);

   if (!$result)
   {
      die("Mysql Select User DB error...");
   }

   if (mysql_num_rows($result) == 0)
   {
      die("DB Error...");
   }

   $data=mysql_fetch_array($result,MYSQL_ASSOC);
   
   return($data["Last_Name"]);
}
//----------------------------------------------------------------------
function getEmpIDFromDB()
{
   global $link;

   $result=mysql_query("select * from employeelist where First_Name='".addslashes($_POST["firstname"])."'",$link);

   if (!$result)
   {
      die("Mysql Select User DB error...");
   }

   if (mysql_num_rows($result) == 0)
   {
      die("DB Error...");
   }

   $data=mysql_fetch_array($result,MYSQL_ASSOC);
   
   return($data["Employee_ID"]);
}
//----------------------------------------------------------------------
function getEmpAddFromDB()
{
   global $link;

   $result=mysql_query("select * from employeelist where First_Name='".addslashes($_POST["firstname"])."'",$link);

   if (!$result)
   {
      die("Mysql Select User DB error...");
   }

   if (mysql_num_rows($result) == 0)
   {
      die("DB Error...");
   }

   $data=mysql_fetch_array($result,MYSQL_ASSOC);
   
   return($data["Address"]);
}
//----------------------------------------------------------------------
function getEmpPosFromDB()
{
   global $link;

   $result=mysql_query("select * from employeelist where First_Name='".addslashes($_POST["firstname"])."'",$link);

   if (!$result)
   {
      die("Mysql Select User DB error...");
   }

   if (mysql_num_rows($result) == 0)
   {
      die("DB Error...");
   }

   $data=mysql_fetch_array($result,MYSQL_ASSOC);
   
   return($data["Position"]);
}
//----------------------------------------------------------------------
function getEmpDoorFromDB()
{
   global $link;

   $result=mysql_query("select * from employeelist where First_Name='".addslashes($_POST["firstname"])."'",$link);

   if (!$result)
   {
      die("Mysql Select User DB error...");
   }

   if (mysql_num_rows($result) == 0)
   {
      die("DB Error...");
   }

   $data=mysql_fetch_array($result,MYSQL_ASSOC);
   
   return($data["Door_No"]);
}
//----------------------------------------------------------------------
function getVisLNameFromDB()
{
   global $link;

   $result=mysql_query("select * from visitorlist where First_Name='".addslashes($_POST["firstname"])."'",$link);

   if (!$result)
   {
      die("Mysql Select User DB error...");
   }

   if (mysql_num_rows($result) == 0)
   {
      die("DB Error...");
   }

   $data=mysql_fetch_array($result,MYSQL_ASSOC);
   
   return($data["Last_Name"]);
}
//----------------------------------------------------------------------
function getVisIDFromDB()
{
   global $link;

   $result=mysql_query("select * from visitorlist where First_Name='".addslashes($_POST["firstname"])."'",$link);

   if (!$result)
   {
      die("Mysql Select User DB error...");
   }

   if (mysql_num_rows($result) == 0)
   {
      die("DB Error...");
   }

   $data=mysql_fetch_array($result,MYSQL_ASSOC);
   
   return($data["Visitor_ID"]);
}
//----------------------------------------------------------------------
function getVisPhoneFromDB()
{
   global $link;

   $result=mysql_query("select * from visitorlist where First_Name='".addslashes($_POST["firstname"])."'",$link);

   if (!$result)
   {
      die("Mysql Select User DB error...");
   }

   if (mysql_num_rows($result) == 0)
   {
      die("DB Error...");
   }

   $data=mysql_fetch_array($result,MYSQL_ASSOC);
   
   return($data["Phone_No"]);
}
//----------------------------------------------------------------------
function getVisPurFromDB()
{
   global $link;

   $result=mysql_query("select * from visitorlist where First_Name='".addslashes($_POST["firstname"])."'",$link);

   if (!$result)
   {
      die("Mysql Select User DB error...");
   }

   if (mysql_num_rows($result) == 0)
   {
      die("DB Error...");
   }

   $data=mysql_fetch_array($result,MYSQL_ASSOC);
   
   return($data["Purpose"]);
}
//----------------------------------------------------------------------
function getVisAddFromDB()
{
   global $link;

   $result=mysql_query("select * from visitorlist where First_Name='".addslashes($_POST["firstname"])."'",$link);

   if (!$result)
   {
      die("Mysql Select User DB error...");
   }

   if (mysql_num_rows($result) == 0)
   {
      die("DB Error...");
   }

   $data=mysql_fetch_array($result,MYSQL_ASSOC);
   
   return($data["Address"]);
}
//----------------------------------------------------------------------
function getVisDoorFromDB()
{
   global $link;

   $result=mysql_query("select * from visitorlist where First_Name='".addslashes($_POST["firstname"])."'",$link);

   if (!$result)
   {
      die("Mysql Select User DB error...");
   }

   if (mysql_num_rows($result) == 0)
   {
      die("DB Error...");
   }

   $data=mysql_fetch_array($result,MYSQL_ASSOC);
   
   return($data["Door_No"]);
}
//=========================================================================================================================================
function showEmpTimeList($function, $action, $submitname)
{
   global $errmsg;

   $formshow  = '<FORM METHOD="POST" ACTION="'.$action.'">';
   $formshow .= '<font color=red>'.$errmsg.'<br><br><br></font>';
   $formshow .= '<TABLE BORDER="0"><TR>';
   $formshow .= '<TD width="250">Employee Name</font></TD>';
   $formshow .= '<TD><SELECT name="empid">';
   $formshow .= EmployeeTimeList();
   $formshow .= '</SELECT></TD></TR>';
   $formshow .= '<TD>Period</TD>';
   $formshow .= '<TD><input type="Text" id=fromdate name=fromdate maxlength="25" size="19">';
   $formshow .= '<a href="javascript:NewCal(\'fromdate\',\'MMDDYYYY\',true,12)">';
   $formshow .= '<img src="images/cal.gif" width="16" height="16" border="0" alt="Pick a date"></a>';
   $formshow .= ' - <input type="Text" id=todate name=todate maxlength="25" size="19">';
   $formshow .= '<a href="javascript:NewCal(\'todate\',\'MMDDYYYY\',true,12)">';
   $formshow .= '<img src="images/cal.gif" width="16" height="16" border="0" alt="Pick a date"></a></TD></TR>';
   $formshow .= '<TD><TD><font color=red>mm-dd-yy</font>';
   $formshow .= '</TABLE>';
   $formshow .= '<P ALIGN=CENTER><BR><BR><INPUT TYPE="SUBMIT" VALUE="'.$submitname.'" NAME="submit"></P>';
   $formshow .= '</FORM>';

   print $formshow;
}
//=========================================================================================================================================
function EmployeeTimeList()
{
   global $link;

   $sql  = "select Employee_ID, First_Name, Last_Name, Position ";
   $sql .= "from employeelist order by Last_Name";

   $result=mysql_query($sql,$link);

   if (!$result)
   {
      die("Mysql List user to DB error...".$sql);
   }

   $select = "";

   while($data=mysql_fetch_array($result,MYSQL_ASSOC))
   {
      
      $select .= '<option value="'.$data["Employee_ID"].'">';
      $select .= $data["Employee_ID"].' - '.$data["Last_Name"].' , '.$data["First_Name"].' - '.$data["Position"].'</option>';
   }

   return($select);
}
?>
